package com.hopu.oa.dao.notemanage;

import com.hopu.oa.entity.notemanage.AoaCatalog;
import com.hopu.oa.entity.notemanage.AoaNoteList;
import com.hopu.oa.entity.management.AoaStatusList;
import com.hopu.oa.entity.management.AoaTypeList;
import com.hopu.oa.entity.process.AoaAttachmentList;
import com.hopu.oa.entity.user.AoaUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AoaNoteListDao {
    int deleteByPrimaryKey(Long noteId);

    int insert(AoaNoteList record);

    int insertSelective(AoaNoteList record);

    AoaNoteList selectByPrimaryKey(Long noteId);

    int updateByPrimaryKeySelective(AoaNoteList record);

    int updateByPrimaryKey(AoaNoteList record);

    /*
      @Description :状态
      @Date   :  2021/11/30
      @Param  : []
      @return : java.util.List<com.hopu.oa.entity.management.AoaStatusList>
     */
    @Select("select * from aoa_status_list where status_id in(8,9) ")
    List<AoaStatusList> findStatus();

    @Select("select * from aoa_type_list where type_id in(5,6,7)")
    List<AoaTypeList> findType();

    //笔记目录
    @Select("select * from aoa_catalog where cata_user_id = #{userId}")
    List<AoaCatalog> findCatalog(Integer userId);

    //笔记
    List<AoaNoteList> findNoteList(Integer userId, Integer catalogId, String baseKey, int index, int size);


    int notesomedelete(String[] noteId);

    @Delete("delete from aoa_note_list where note_id = #{noteId}")
    int noteDeleteById(int noteId);

    @Select("select * from aoa_catalog where cata_user_id = #{userId}")
    List<AoaCatalog> queryCatalogByUserId(Integer userId);

    @Select("select * from aoa_catalog where cata_user_id = #{userId} and catalog_id = #{catalogId}")
    AoaCatalog findCatalogById(Integer userId, Integer catalogId);

    //查catalog id
    @Select("select catalog_id from aoa_catalog where catalog_name = #{catalogName} and cata_user_id = #{userId}  ")
    Integer queryCatalogIdByName(Integer userId, String catalogName);

    //type Id
    @Select("select type_id from aoa_type_list where type_name = #{typeName}")
    Integer queryTypeIdByName(String typeName);

    //status id
    @Select("select status_id from aoa_status_list where status_model = 'aoa_note_list' and status_name = #{statusName}")
    Integer queryStatusIdByName(String status);


    @Update("update aoa_note_list set content=#{content} ,title = #{title},status_id = #{statusId},type_id = #{typeId},catalog_id = #{catalogId} where note_id = #{noteId}")
    int notesave(AoaNoteList note);

    @Update("update aoa_note_list set is_collected = #{collected} where note_id = #{id} ")
    int setNoteCollected(String id, String collected);

    @Insert("insert into aoa_catalog(parent_id,catalog_name,cata_user_id) values(1,#{name},#{userId})")
    int insertCatalog(Integer userId, String name);

    @Delete("delete from aoa_catalog where catalog_id = #{id}")
    int deleteCatalogById(String id);


    List<AoaNoteList> queryShareNote(Integer userId, int index, int size);


    List<AoaUser> findUserInfoByName(String userName, @Param("index") int index, @Param("size") int size, int roleId);

    List<AoaNoteList> queryNoteByType(Integer userId, String tId, int index, int size);


    @Select("select * from aoa_attachment_list where attachment_id = #{id} ")
    AoaAttachmentList queryAttByNoteId(Integer id);


    @Select("select createman_id from aoa_note_list where note_id = #{noteId}")
    Integer quertNoteUserIdByNoteId(String noteId);


    //修改收藏
    @Update("update   aoa_note_list set is_collected = 1 where note_id = #{noteId}")
    int updateCollectBynoteId(String noteId);

    @Select("select u.user_name from aoa_user u join aoa_note_list n ON u.user_id = n.createman_id where n.note_id = #{catalogId}")
    String queryNoteCreateUserNameByNoteId(String catalogId);

    @Select("select type_id from aoa_note_list where note_id = #{catalogId}")
    int queryNoteTypeIdByNoteId(String catalogId);
}